package com.zgm.ch04.applicationContext.i18n._9_5_2_1;

import java.util.Locale;

import net.sf.cglib.core.Local;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ErrorReportingDemo {

	private static void run(ApplicationContext context, Locale locale, ErrorReport reporter,
							double[] values){
		try {
			reporter.evaluate(values);
			System.out.println("\n Success");
		} catch (SourceDateInvalidException ex) {
			ex.printStackTrace();
		} catch (ArgumentDomainException ex) {
			ex.printStackTrace();
		}
		
		//
		/*reporter.evaluate(values);
		System.out.println("\n Success");*/
		
	}
	
	public static void main (String[] args){
		ApplicationContext ctx = new ClassPathXmlApplicationContext("com/zgm/ch04/applicationContext/i18n/_9_5_2_1/_9_5_2_1-context.xml");
		
		ErrorReport reporter = (ErrorReport) ctx.getBean("errorReport");
		Locale en_GB = new Locale("en", "GB");
		Locale zh_CN = new Locale("zh", "CN");
		
		run(ctx, en_GB, reporter, new double[] {1});
		run(ctx, en_GB, reporter, new double[] {1, -2});
		run(ctx, en_GB, reporter, new double[] {1, 3});
		run(ctx, zh_CN, reporter, new double[] {1});
		run(ctx, zh_CN, reporter, new double[] {1, -2});
		run(ctx, zh_CN, reporter, new double[] {1, 3});
	}
}
